#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    int num = 3;

    char filename[128] = {0};
    while(1) {
        sprintf(filename, "tmp_%04d", num++);

        if(open(filename, O_RDONLY | O_CREAT, 0777) < 0) {
            perror("open error: ");
            break;
        }
    }
    
    printf("num = %d\n", num);

    return 0;
}

